﻿@using zichan.Entity
@using zichan.Common;
@model IPagedList<Asset>
@{
    ViewBag.Title = "数据管理列表";
}

@section Pagetitle{
    @AdminCommon.PageTitle("数据管理列表", "添加/删除/修改")
}
<style>
    .c_Box {
        display: none;
    }

    #pagebar li {
        display: inline-block;
    }
</style>
<div class="portlet">
    <div class="portlet-title">
        <div class="caption ">
            <i class="fa fa-table"></i>数据管理列表
        </div>
        <div class="actions pull-left leftMargin">
            @if (zichan.Common.PowerHelp.Check("Assetes", "create"))
            {
                <a href="@Url.Action("create", "Assetes")" class="btn default yellow-stripe">
                    <i class="fa fa-plus"></i>
                    <span class="hidden-480">添加数据</span>
                </a>
            }
        </div>
       
        <div class="actions pull-left leftMargin">
            @if (zichan.Common.PowerHelp.Check("Assetes", "AssetAndPutServer"))
            {
                <a href="@Url.Action("AssetAndPutServer", "Assetes")" class="btn default yellow-stripe">
                    <i class="fa fa-plus"></i>
                    <span class="hidden-480">添加已有服务器</span>
                </a>
            }
        </div>
    </div>
    <div class="portlet-body">
        <div class="table-container">
            <div class="dataTables_wrapper dataTables_extended_wrapper no-footer">
                <div class="row">
                    <div class="col-sm-12">
                        <div class="table-group-actions pull-left">
                            @using (Html.BeginForm("index", "Assetes", FormMethod.Get, new { @class = "form-inline" }))
                            {
                                <input type="hidden" name="pageSize" value="@ViewBag.pageSize" />
                                <div class="form-group">
                                    <input type="text" placeholder="请输入资产编号" name="code" value="@ViewBag.code" class="form-control input-small input-sm" />
                                </div>
                                <div class="form-group">
                                    <input type="text" placeholder="请输入资产名称" name="name" value="@ViewBag.name" class="form-control input-small input-sm" />
                                </div>
                                <div class="form-group">
                                    @Html.DropDownList("assetClassId", (SelectList)ViewBag.assetClassIds, "全部资产分类", new { @class = "form-control input-small input-sm" })
                                </div>
                                <div class="form-group">
                                    @Html.DropDownList("companyId", (SelectList)ViewBag.companyIds, "全部公司", new { @class = "form-control input-small input-sm" })
                                </div>
                                <div class="form-group">
                                    <div class="input-group">
                                        <input type="text" placeholder="采购时间" name="sdt" id="sdt" value="@ViewBag.sdt" class="form-control input-small input-sm dateSdt" />
                                        <span class="input-group-addon dateSdt">
                                            <i class="fa fa-calendar bigger-110 "></i>
                                        </span>
                                    </div>
                                    至
                                    <div class="input-group">
                                        <input type="text" placeholder="采购时间" name="edt" id="edt" value="@ViewBag.edt" class="form-control input-small input-sm dateEdt" />
                                        <span class="input-group-addon dateEdt">
                                            <i class="fa fa-calendar bigger-110"></i>
                                        </span>
                                    </div>
                                </div>
                                <button class="btn btn-sm yellow table-group-action-submit"><i class="fa fa-check"></i> 搜索</button>
                            }
                        </div>
                    </div>
                </div>
                <div class="form-group"><h5>列表总数:<span style="color:red;">@Model.TotalItemCount</span></h5></div>
                <div class="table-scrollable">
                    <table class="table  table-hover">
                        <thead>
                            <tr class="heading">
                                <th class="c_Box"><input data-IsStorage="1" id="All_check" type="checkbox" /></th>
                                <th>资产编号</th>
                                <th>资产分类</th>
                                <th>资产名称</th>
                                <th>所属公司</th>
                                <th>采购人</th>
                                <th>采购时间</th>
                                <th>数据录入时间</th>
                                <th>操作</th>
                            </tr>
                        </thead>
                        <tbody>
                            @foreach (Asset r in Model)
                            {
                                <tr>
                                    <td class="c_Box"><input name="checkbox" type="checkbox" data-IsStorage="@r.IsStorage" id="@r.Id" @*@(r.ProposerId != Uid ? "disabled" : "false")*@ /></td>
                                    <td>@r.Code</td>
                                    <td>@r.AssetClassName</td>
                                    <td>@r.Name</td>
                                    <td>@r.CompanyName</td>
                                    <td>@r.BuyerName</td>
                                    <td>@(string.Format("{0:yyyy-MM-dd}", r.BuyTime))</td>
                                    <td>@(string.Format("{0:yyyy-MM-dd}", r.UploadTime))</td>
                                    <td>
                                        @if (PowerHelp.Check("Assetes", "ImproveInformation") && r.IsStorage == 0)
                                        {
                                            <a href="@Url.Action("ImproveInformation", "Assetes", new {id=r.Id })" class="btn default btn-xs purple">
                                                <i class="fa fa-edit"></i> 完善信息
                                            </a>
                                        }
                                        @if (PowerHelp.Check("Assetes", "Information") && r.IsStorage == 1)
                                        {
                                            <a href="@Url.Action("Information", "Assetes", new {id=r.Id })" class="btn default btn-xs purple">
                                                <i class="fa fa-search"></i> 详情
                                            </a>
                                        }
                                        @if (PowerHelp.Check("Assetes", "put") && r.IsStorage == 1)
                                        {
                                            <button onclick="put_confirm(@r.Id)" class="btn default btn-xs purple">
                                                <i class="fa fa-edit"></i> 入库
                                            </button>
                                        }

                                        @if (PowerHelp.Check("Assetes", "delete"))
                                        {
                                            @*<a href="@Url.Action("delete", "Assetes", new { id = r.Id })" class="btn default btn-xs black">*@
                                            <a class="btn default btn-xs black" href="javascript:if(confirm('确定要删除@(r.Name)?'))location='/Assetes/delete?id=@r.Id'">
                                                <i class="fa fa-trash-o"></i> 删除
                                            </a>
                                        }
                                    </td>
                                </tr>
                            }
                        </tbody>
                    </table>
                </div>
                @if (Model.TotalItemCount > 0 && zichan.Common.PowerHelp.Check("Assetes", "BatchPut") && zichan.Common.PowerHelp.Check("Assetes", "BatchDelete"))
                { <div class="row">
                    <div class="col-md-3 ">
                        @Html.DropDownList("checkBoxs", (SelectList)ViewBag.checkBoxs, "请选择批量操作", new { @class = "form-control input-medium input-sm" })
                    </div>
                    <div class="col-md-3" style="display:none;" id="sure_div">
                        <button class="btn green" id="sure_checkBoxs">确定操作</button>
                    </div>
                </div>}
                <div class="row">
                    <div class="col-sm-12 dataTables_paginate">
                        <div class="pull-right">
                            <ul id="pagebar" style="display:inline-block;margin-right:10px;color:#3175AF;">
                                <li>
                                    每页<select name="pageSize" id="pageSize" class="select2" style="width:50px;font-size:18px;">
                                        <option value="@ViewBag.pageSize">@ViewBag.pageSize</option>
                                        @foreach (var s in ViewBag.pageSizes)
                                        {
                                            <option value="@s.Value">@s.Text</option>
                                        }
                                    </select>个
                                </li>
                                <li>第@(Model.PageNumber)/共@(Model.PageCount)页</li>
                                @using (Html.BeginForm("index", "Assetes", FormMethod.Get, new { @style = "display: inline-block;" }))
                                {
                                    <li style="display:none;">
                                       <input type="hidden" name="pageSize" value="@ViewBag.pageSize"/>
                                        <input type="hidden" name="name" value="@ViewBag.name" />
                                        <input type="hidden" name="code" value="@ViewBag.code" />
                                        <input type="hidden" name="assetClassId" value="@ViewBag.assetClassId" />
                                        <input type="hidden" name="companyId" value="@ViewBag.companyId" />
                                        <input type="hidden" name="sdt" value="@ViewBag.sdt" />
                                        <input type="hidden" name="edt" value="@ViewBag.edt" />
                                        @Html.TextBox("pageCount", Model.PageCount)
                                    </li>
                                            <li>跳转至<input name="selectedPage" style="width:40px;font-size:18px;" value="@ViewBag.selectedPage" />页</li>
                                            <li><button type="submit">GO</button></li>}
                            </ul>
                            @if (Model.PageCount > 1)
                            {
                                <ul id="pagebar" class="pagination" style="margin:0px;float:right;">
                                    <li><a href="@Url.Action("Index", "assetes", new { code = ViewBag.code, name = ViewBag.name, assetClassId = ViewBag.assetClassId, companyId = ViewBag.companyId, sdt = ViewBag.sdt, edt = ViewBag.edt,pageSize=ViewBag.pageSize, page = 1 })">首页</a></li>
                                    <li>@Html.ActionLink("上一页", "Index", "assetes", new { code = ViewBag.code, name = ViewBag.name, assetClassId = ViewBag.assetClassId, companyId = ViewBag.companyId, sdt = ViewBag.sdt, edt = ViewBag.edt, pageSize = ViewBag.pageSize, page = Model.PageNumber - 1 }, null)</li>
                                    <li>@Html.ActionLink("下一页", "Index", "assetes", new { code = ViewBag.code, name = ViewBag.name, assetClassId = ViewBag.assetClassId, companyId = ViewBag.companyId, sdt = ViewBag.sdt, edt = ViewBag.edt, pageSize = ViewBag.pageSize, page = (Model.PageNumber + 1 < Model.PageCount ? Model.PageNumber + 1 : Model.PageCount) }, null)</li>
                                    <li>@Html.ActionLink("末页", "Index", "assetes", new { code = ViewBag.code, name = ViewBag.name, assetClassId = ViewBag.assetClassId, companyId = ViewBag.companyId, sdt = ViewBag.sdt, edt = ViewBag.edt, pageSize = ViewBag.pageSize, page = Model.PageCount }, null)</li>
                                </ul>}
                        </div>

                    </div>
                </div>

            </div>

        </div>
    </div>
</div>
@section footer{
    <script src="/assets/global/plugins/bootstrap-datetimepicker/js/bootstrap-datetimepicker.min.js" type="text/javascript"></script>
    <script src="~/Scripts/layer/layer.js"></script>
<script src="~/Scripts/AssetJs.js"></script>
    <script type="text/javascript">
        //$(".form_datetime").datetimepicker({
        //    format: "dd MM yyyy - hh:ii"
        //});
        var formatDateTime = function (date) {
            var y = date.getFullYear();
            var m = date.getMonth() + 1;
            var d = date.getDate();
            return y + '/' + m + '/' + d;
        };
        $('.dateSdt').datetimepicker({
            //language: 'zh-CN',
            weekStart: 1,
            todayBtn: 0,
            autoclose: 1,
            todayHighlight: 1,
            startView: 2,
            forceParse: 0,
            minView: 'month',　　　　//日期时间选择器所能够提供的最精确的时间选择视图。
            format: 'yyyy/m/d'
        }).on('changeDate', function (ev) {
            $("#sdt").val(formatDateTime(new Date(ev.date.valueOf() - 28800000)));
        });
        $('.dateEdt').datetimepicker({
            //language: 'zh-CN',
            weekStart: 1,
            todayBtn: 0,
            autoclose: 1,
            todayHighlight: 1,
            startView: 2,
            forceParse: 0,
            minView: 'month',　　　　//日期时间选择器所能够提供的最精确的时间选择视图。
            format: 'yyyy/m/d'
        }).on('changeDate', function (ev) {
            $("#edt").val(formatDateTime(new Date(ev.date.valueOf() - 28800000)));
        });
        //$(function () {
        //    $('#pageSize').on("change", function () {
        //        var name = $("input[name='name']").val();
        //        var assetClassId = $("input[name='assetClassId']").val();
        //        var companyId = $("input[name='companyId']").val();
        //        var code = $("input[name='code']").val();
        //        var sdt = $("input[name='sdt']").val();
        //        var edt = $("input[name='edt']").val();
        //        var size = $(this).val();
        //        location.href = "/assetes/Index?code=" + code + "&name=" + name + "&assetClassId=" + assetClassId + "&companyId=" + companyId + "&sdt=" + sdt + "&edt=" + edt + "&pageSize=" + size;
        //    });
        //    $("#checkBoxs").on("change", function () {
        //        if ($(this).val() > 0) {
        //            $("#sure_div").css({ "display": "block" });
        //            $(".c_Box").css({ "display": "block" });
        //            //$(".table th:last").css( "display", "none" );
        //            //$(".table tr").each(function(){$(this).children(":last").css({ "display": "none" })});
        //            if ($(this).val() == 1) {
        //                $(".c_Box").each(function () {
        //                    $(this).children().removeAttr("checked");
        //                    if ($(this).children().attr("data-IsStorage") != 1) {
        //                        $(this).children().attr("disabled", "");
        //                    }
        //                });
        //            }
        //            else {
        //                $(".c_Box").each(function () {
        //                    $(this).children().removeAttr("checked");
        //                    $(this).children().removeAttr("disabled");
        //                });
        //            }
        //        }
        //        else {
        //            //$(".table tr").each(function(){$(this).children(":last").css({ "display": "block" })});  
        //            $("#sure_div").css({ "display": "none" });
        //            $(".c_Box").css({ "display": "none" });
        //        }
        //    });
        //    $("#All_check").on("click", function () {
        //        if ($(this).prop("checked")) {
        //            $("input[name='checkbox']").not("[disabled]").prop("checked", "true");
        //        }
        //        else {
        //            $("input[name='checkbox']").removeAttr("checked");
        //        }
        //    });
            
        //    $("#sure_checkBoxs").on("click", function () {
        //        var len = $("td input:checked").length;
        //        if (len <= 0) {
        //            alert("请选择数据");
        //        }
        //        else {
        //            var str = "";
        //            $("td input:checked").each(function () {
        //                str = str + "," + $(this).attr("id");
        //            });
        //            if ($("#checkBoxs").val() == 1) {
        //                $.post("/Assetes/BatchPut", { ids: str }, function (result) {
                           
        //                    location.reload();
        //                });
        //            }
        //            else {
        //                $.post("/Assetes/BatchDelete", { ids: str }, function () {
        //                    location.reload();
        //                });
        //            }
        //        }
        //    });
        //});
        //function put_confirm(assetId) {
        //    var r = confirm("确定入库？")
        //    if (r == true) {
        //        layer.open({
        //            type: 1, //加上边框
        //            area: ['220px', '100px'], //宽高
        //            content: '正在入库，请稍后...'
        //        });
        //        setTimeout(function () {
        //            $.post("/Assetes/Put", { id: assetId }, function (result) {
        //                //var data=JSON.parse(result);
        //                //alert(data);
        //                //if(result==0)
        //                //{
        //                //    alert("入库成功");
        //                //}
        //                //else{
        //                //    alert("入库失败");
        //                //}
        //                location.reload();
        //            });
        //        }, 1000);
        //    }
        //}
    </script>
}
